/**
/**** <p>Title: 分页技术</p>
* <p>Company: 北京福富软件技术股份有限公司福州分公司</p>
* @author huangjx
* @mail g.huangjx@ffcs.cn hjx615@163.com 
* @version 1.0
*/
var initPage="str=1&str=10&str=1";//产品运营中心临时改的
function chagePageInfo(va){
	initPage=initPage.substring(0,10)+va+initPage.substring(initPage.length-6,initPage.length);
}
function mychecknum(obj){
	var reg2=/^\d{0,100}$/;  
   if(!reg2.test(obj.value)){
   		myCurrentOnePageCount.value="";
   }
}
function StringBuffer()    
{    
    this._strings = [];    
    if(arguments.length==1)    
    {    
        this._strings.push(arguments[0]);    
    }    
}    
   
StringBuffer.prototype.append = function(str)    
{    
    this._strings.push(str);    
    return this;    
}    
   
StringBuffer.prototype.toString = function()    
{    
    return this._strings.join("");    
}    
   
/* 返回长度 */   
StringBuffer.prototype.length = function()    
{    
    var str = this._strings.join("");    
    return str.length;    
}    
   
/* 删除后几位字符 */   
StringBuffer.prototype.del = function(num)    
{    
    var len = this.length();    
    var str = this.toString();    
    str     = str.slice(0,len-num);    
    this._strings = [];    
    this._strings.push(str);    
}   

var myClass="mylink";
var mytest="mytest";
function gotoPage(curPageStr,fenYeId){
    if(!curPageStr) return;//go button input value is space;
	var formObj;
	var url="";
	var fenYe=document.getElementById(fenYeId);
	//alert(fenYe.pageInfo);
	//alert(fenYe.funName);
	if(fenYe.funName){
		eval(fenYe.funName+"('"+getUrlParamenter(curPageStr,fenYeId)+"')");
		return;
	}
	if(fenYe.formName){
		formObj=document[fenYe.formName];
	}
	if(fenYe.formId){
		formObj=document.getElementById(fenYe.formId);
	}
	
	if(formObj==null&&document.forms[0]){
		formObj=document.forms[0];
	}
	if(!fenYe.url){//表单请求
		if(formObj.action.indexOf("?")==-1){
			formObj.action+="?"+getUrlParamenter(curPageStr,fenYeId);
		}else{
			formObj.action+="&"+getUrlParamenter(curPageStr,fenYeId);
		}
		formObj.submit();
	}else{//url请求
		url=fenYe.url;
		if(url.indexOf("?")==-1){
			url+="?"+getUrlParamenter(curPageStr,fenYeId);
		}else{
			url+="&"+getUrlParamenter(curPageStr,fenYeId);
		}
		window.location=url;
	}
}
function changePageCout(curPageStr,fenYeId){
    var fenYe=document.getElementById(fenYeId);
    fenYe.setAttribute("onePageCount",document.getElementById("onePageCount").value);
	//var a=event.keyCode;  
	//if(a=='13'){ 
	    gotoPage(curPageStr,fenYeId);
	//}
    
}
function getUrlParamenter(curPageStr,fenYeId){
    var fenYe=document.getElementById(fenYeId);
	var pageInfo=fenYe.pageInfo;
	var pageInfoArr=pageInfo.split(",");
	var totalRows=parseInt(pageInfoArr[0]);//总条数
	if(document.getElementById("onePageCountPoc")){
		fenYe.setAttribute("onePageCount",document.getElementById("onePageCount").value);//产品运营中心临时改的
	}
	var onePageCount=parseInt(fenYe.getAttribute("onePageCount"));//支持多个分页
	var curPage=parseInt(curPageStr);
	var pageCount=parseInt((totalRows+onePageCount-1)/onePageCount);//总页数
	var firstPage=totalRows+","+onePageCount+",1,0,"+onePageCount;
	if(curPage<1) curPage=1;//小于首页
	if(curPage>pageCount) curPage=pageCount;//大于总页
	//var urlParameter=totalRows+","+onePageCount+","+(curPage)+","+onePageCount*(curPage-1)+","+onePageCount;//pageInfo 发送
	var urlParameter="str="+totalRows+"&str="+onePageCount+"&str="+curPage;//str发送
	return urlParameter;
}
//pageInfo="总条数+一页条数+当前页+FirstResult+maxResult
function getFenYe(fenYeId,delRows){
    var selectstr="";
    var returnPageInfo="";
    if(!document.getElementById(fenYeId)){
    	return;
    }
    var fenYe=document.getElementById(fenYeId);
	var pageInfo=fenYe.pageInfo;
	var pageInfoArr=pageInfo.split(",");
	var totalRows=parseInt(pageInfoArr[0]);//记录总数
	//if(totalRows==0) {
		//fenYe.innerHTML="<a href='#'>总共"+0+"页"+0+"条</a>";
		//return;
	//}
	if(delRows){//删除记录刷新分页
		totalRows-=parseInt(delRows);
		fenYe.pageInfo=totalRows+","+pageInfoArr[1]+","+pageInfoArr[2];
	}
	var onePageCount=parseInt(pageInfoArr[1]);//一页条数
	fenYe.setAttribute("onePageCount",onePageCount);//支持多个分页
	var curPage=parseInt(pageInfoArr[2]);//当前页
	var pageCount=parseInt((totalRows+onePageCount-1)/onePageCount);//总共页数
	returnPageInfo=totalRows+","+onePageCount+","+(curPage)+","+onePageCount*(curPage-1)+","+onePageCount;
	var str=new StringBuffer();
	str.append("<table width=100% border=0 background='/telecom/common/fenye_021.gif'><tr><td align='right'>");
	str.append("&nbsp;<font class='"+myClass+"' >");
	//str.append("</td><td align='right'>");
///	if(curPage!=1){
		str.append("<a href=javascript:gotoPage('1','"+fenYeId+"')>首页</a>&nbsp;");
		str.append("<a href=javascript:gotoPage('"+(curPage-1)+"','"+fenYeId+"')>上一页</a>&nbsp;");
	//}
	//if(pageCount!=curPage){
		str.append("<a href=javascript:gotoPage('"+(curPage+1)+"','"+fenYeId+"')>下一页</a>&nbsp;");
		str.append("<a href=javascript:gotoPage('"+(pageCount)+"','"+fenYeId+"')>尾页</a>&nbsp;");
	//}
	str.append("<font class='"+myClass+"' >第"+curPage+"页&nbsp;共"+pageCount+"页&nbsp;总"+totalRows+"条记录");
	str.append("&nbsp;每页"+onePageCount+"条");
	selectstr+=("<font class='"+myClass+"' style='display:none'>转跳</font><select style='height:0px;display:none'");
	for(i=1;i<pageCount+1;i++){
	    if(i==curPage){
			selectstr+=("<option selected value='"+i+"'>"+i+"</option>");
		}else{
			selectstr+=("<option value='"+i+"'>"+i+"</option>");
		}
	}
	selectstr+=("</select>&nbsp;");
	str.append(selectstr);
	str.append("<input style='display:none' type='text' size='3' onkeydown=mychecknum(this) onchange=mychecknum(this) id='myCurrentOnePageCount'/>"); 
	str.append("<input style='display:none' type='button' value='GO' class='btn1' onclick=gotoPage(document.all[this.sourceIndex-1].value,'"+fenYeId+"')>"); //支持多个分页
	fenYe.changeCount="false";//不改变页面条数
	if(!fenYe.changeCount){
		str.append("<a class='"+myClass+"'>条数</a><select  style='height:0px;' id='onePageCount' pageInfo="+fenYeId+" onchange=changePageCout(1,this.pageInfo)>");
	}else{
		str.append("<a style='display:none' class='"+myClass+"'>条数</a><select  style='display:none' id='onePageCount' pageInfo="+fenYeId+" onchange=changePageCout(1,this.pageInfo)>");
	}
	str.append("<option value='5'>5</option>");
	if(onePageCount==10){
		str.append("<option value='10' selected>10</option>");
	}else{
		str.append("<option value='10' >10</option>");
	}
	if(onePageCount==15){
		str.append("<option value='15' selected>15</option>");
	}else{
		str.append("<option value='15' >15</option>");
	}
	if(onePageCount==20){
		str.append("<option value='20' selected>20</option>");
	}else{
		str.append("<option value='20' >20</option>");
	}
	if(onePageCount==50){
		str.append("<option value='50' selected>50</option>");
	}else{
		str.append("<option value='50' >50</option>");
	}
	if(onePageCount==100){
		str.append("<option value='100' selected>100</option>");
	}else{
		str.append("<option value='100' >100</option>");
	}
	if(onePageCount==200){
		str.append("<option value='200' selected>200</option>");
	}else{
		str.append("<option value='200' >200</option>");
	}
	if(onePageCount==500){
		str.append("<option value='500' selected>500</option>");
	}else{
		str.append("<option value='500' >500</option>");
	}
	if(onePageCount==1000){
		str.append("<option value='1000' selected>1000</option>");
	}else{
		str.append("<option value='1000' >1000</option>");
	}
	str.append("</select>&nbsp;");
	//str.append("<font class='"+myClass+"' >总共"+pageCount+"页"+totalRows+"条</font>");
	str.append("</td></tr></table>");
	//alert(str.toString());
	fenYe.innerHTML=str.toString();
	return returnPageInfo;
}
getFenYe("fenYe");
